<%-- 
    Document   : index
    Created on : 2009-01-13, 23:49:48
    Author     : pzietek
--%>

<%@page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.sql.ResultSet" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<fmt:setBundle basename="pl.wat.main.Properties" var="bundle" scope="session"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
        <link rel="stylesheet" href="style.css" type="text/css">
        <title>SQL2chart Application</title>
    </head>
    <body>
        <form action="ActionController" method="post">            
        <input type="hidden" name="action" value="execute"/>
        <input type="hidden" name="actiondetails" value="execute"/>

            <table width="800px" align="center">
                <tr>
                    <td align="center">
                        <fmt:message key="main.sqlquery" bundle="${bundle}"/>
                    </td>
                </tr>
                 <tr>
                    <td align="left">
                        <textarea cols="100" rows="5" name="query"><%
                        String querry = (String) request.getAttribute("que");                        
                        if(querry != null && !querry.equals("")){
%><%=querry%>
<%
                        }
%></textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <input type="submit" value="<fmt:message key="main.submit" bundle="${bundle}"/>">
                    </td>
                </tr>

<%  
                if(request.getParameter("query")!=null && !request.getParameter("query").equals("")){
%>
                <tr>
                <table border="1" align="center">
<%
                 ResultSet rs = (ResultSet) request.getAttribute("rs");
                 int x = rs.getMetaData().getColumnCount();
%>
                 <tr>
<%
                    for(int i=1; i<=x; i++){
%>                   
                        <td>
                            <b><font size="1"><%= rs.getMetaData().getColumnName(i) %></font></b>
                        </td>
<%                  }
%>
                  </tr>
<%

                 while(rs.next())
                 {
%>
                 <tr>
<%
                    for(int i=1; i<=x; i++){
%>                   
                        <td>
                            <font size="1"><%= rs.getString(i) %></font>
                        </td>
<%                  }
%>
                  </tr>
<%
                 }
%>
                </table>
                </tr>
                <br>
                <table align="center">
                <tr>
                    <td colspan="2" align="center">
                        <input type="submit" name="action1" value="Zatwierdz">
                    </td>
                </tr>
                </table>
<%
                }
%>

            </table>

        </form>
        
    </body>
</html>
